export const initState = {
    info:sessionStorage.getItem("isLogin")?JSON.parse(sessionStorage.getItem("isLogin")):{}
}

export const reducer = (state, action) => {
    switch (action.type) {
        case "changeUserInfo":
            return {
                ...state,
                info:action.info
            }
        default:
            return state
    }
}

export const actions = {
    changeUserInfo:info=>{
        if(info.token){
            sessionStorage.setItem("isLogin",JSON.stringify(info))
        }else{
            sessionStorage.removeItem("isLogin")
        }
        return ({type:"changeUserInfo",info})
    }
}